home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 11, No. 01 (1990-01)(MindCraft Publishing)(Side A)[a].zip / Nibble Volume 11, No. 01 (1990-01)(MindCraft Publishing)(Side A)[a].po / FR.OPTIONS.ASM.txt < prev    next >
Text File  |  1996-12-24  |  32KB  |  818 lines

  1. ****************************************
  2. *                                      *
  3. *    FR.OPTIONS.ASM Source Code        *
  4. *          by Sandy Mossberg           *
  5. *                                      *
  6. *            APW Assembler             *
  7. *                                      *
  8. *          Copyright (C) 1989          *
  9. *       by MindCraft Publ. Corp.       *
  10. *          Concord, MA  01742          *
  11. *                                      *
  12. ****************************************
  13.  
  14. *****************************************************************
  15. *
  16. DoOpen      start
  17. *
  18. * Open window containing file contents:
  19. *
  20. *****************************************************************
  21.             using    GlobalData
  22.  
  23.             PushWord #120            ;X coord of upper left corner
  24.             PushWord #40             ;Y coord of upper left corner
  25.             PushLong #SFPrompt       ;ptr to prompt string
  26.             PushLong #0              ;ptr to filter (none)
  27.             PushLong #SFTypeList     ;ptr to file type list
  28.             PushLong #SFReplyRec     ;ptr to reply record
  29.             _SFGetFile
  30.  
  31.             lda      SFGood          ;which button closed box?
  32.             beq      Done            ;Cancel button hit
  33.  
  34.             PushWord #257            ;Okay button hit
  35.             _DisableMItem            ;dim Open File item
  36.  
  37.             jsr      GetFile         ;read selected file into memory
  38.             jsr      ShowWindow      ;display window
  39. Done        rts
  40. ;................................................................
  41. ;
  42. GetFile     anop
  43. ;
  44. ; Read selected Ascii file into memory:
  45. ;
  46. ; Convert file name P-string in standard files reply record to
  47. ; class 1 GS/OS input str at MyFile (i.e. change leading length
  48. ; byte to leading length word). Also convert same P-string
  49. ; to title of text window (i.e. flank file name with spaces
  50. ; because window will contain racing stripes in title bar):
  51.  
  52.             short
  53.             lda      SFFilename      ;get length byte of P-string
  54.             sta      MyFile          ;put leading length word
  55.             stz      MyFile+1        ; in input string
  56.             clc                      ;bump length byte by 2 in wind
  57.             adc      #2              ; title string to accommodate
  58.             sta      TextWindStr     ; leading and trailing spaces
  59.             lda      #$20            ;put leading space
  60.             sta      TextWindStr+1   ; in window title
  61.             ldy      #0              ;copy file name to
  62. GF01        lda      SFFilename+1,y  ; both locations
  63.             cmp      #$60
  64.             bcc      GF02
  65.             and      #$DF            ;ensure upper case
  66. GF02        sta      MyFile+2,y
  67.             sta      TextWindStr+2,y
  68.             iny
  69.             cpy      SFFilename
  70.             bcc      GF01
  71.             lda      #$20            ;put trailing space
  72.             sta      TextWindStr+2,y ; in window title
  73.             long                     ;set 16-bit regs
  74.  
  75. ; Read file into memory:
  76.  
  77.             _OpenGS  OpenParm        ;open selected file
  78.             jsr      HandlErr
  79.             lda      OpenRefNum      ;stuff reference number
  80.             sta      EOFRefNum       ; into other parmlists
  81.             sta      ReadRefNum
  82.             sta      CloseRefNum
  83.  
  84.             _GetEOFGS EOFParm        ;get size of file in bytes
  85.             jsr      HandlErr
  86.             lda      EOF             ;stuff file size into
  87.             sta      RequestCnt      ; Read parmlist
  88.             lda      EOF+2
  89.             sta      RequestCnt+2
  90.  
  91.             anop                     ;reserve memory for data buffer
  92.             PushLong #0              ;space for result
  93.             PushLong EOF             ;size of space
  94.             PushWord MasterID        ;master ID
  95.             PushWord #$C010          ;locked, fixed, one bank
  96.             PushLong #0              ;not used
  97.             _NewHandle               ;allocate space
  98.             jsr      HandlErr
  99.             PullLong DataBufHndl     ;save handle to data buffer
  100.  
  101.             lda      [DataBufHndl]   ;dereference handle and
  102.             sta      DataBufPtr      ; store ptr to data buffer
  103.             sta      DataBuf         ; in Read parmlist
  104.             ldy      #2
  105.             lda      [DataBufHndl],y
  106.             sta      DataBufPtr+2
  107.             sta      DataBuf+2
  108.  
  109.             _ReadGS  ReadParm        ;read file into data buffer
  110.             jsr      HandlErr
  111.  
  112.             _CloseGS CloseParm       ;close file
  113.             jmp      HandlErr
  114. ;................................................................
  115. ;
  116. ShowWindow  anop
  117. ;
  118. ; Display window on SHR screen:
  119. ;
  120. ; Calculate data height of file in pixels,
  121. ; and ensure positive Ascii file bytes:
  122.  
  123.             lda      #9*2            ;allow top and bottom margins
  124.             sta      DataSize        ; (row = 9 pixels)
  125.             ldy      #0              ;zero char index
  126. SW01        lda      [DataBufPtr],y  ;get 2 bytes from file buffer
  127.             and      #$FF7F          ;ensure pos Ascii lo byte
  128.             sta      [DataBufPtr],y  ;write char back to file buffer
  129.             and      #$FF            ;ignore hi byte
  130.             cmp      #$0D
  131.             bne      SW02            ;CR not found
  132.             clc
  133.             lda      DataSize        ;CR found so add 9 pixels
  134.             adc      #9              ; for another line
  135.             sta      DataSize
  136. SW02        iny                      ;bump char index
  137.             cpy      EOF
  138.             bcc      SW01            ;not yet at end of file
  139.  
  140.             cmp      #$3FFF          ;max window height = 16383
  141.             bcc      SW03            ;max height not exceeded
  142.  
  143. ; Entire file cannot be displayed because of QuickDraw II limits,
  144. ; so check whether user wishes to display partial file:
  145.  
  146.             pha                      ;space for result
  147.             PushWord #0              ;C-string
  148.             PushLong #0              ;no substitution array
  149.             PushLong #AlertStr       ;ptr to alert string
  150.             _AlertWindow             ;display alert window
  151.             pla                      ;get button ID
  152.             dec      a
  153.             beq      SW04            ;Cancel button hit
  154.  
  155.             lda      #$3FFF          ;user wants partial file shown;
  156.             sta      DataSize        ; clip window to max height
  157.  
  158. ; Display window:
  159.  
  160. SW03        PushLong #0              ;space for result
  161.             PushLong #TextWind       ;ptr to window parmlist
  162.             _NewWindow               ;display window
  163.             jsr      HandlErr
  164.             PullLong TextWindPtr     ;save ptr to window's GrafPort
  165.             rts
  166.  
  167. ; Cancel window:
  168.  
  169. SW04        PushLong DataBufHndl     ;handle to file data buffer
  170.             _DisposeHandle           ;release handle and free memory
  171.             rts
  172. ;................................................................
  173. ;
  174. ; DoOpen data:
  175. ;
  176. SFReplyRec  anop                     ;standard files reply record
  177. SFGood      ds       2               ;true = open, false = cancel
  178. SFFileType  ds       2               ;file type code
  179. SFAuxtype   ds       2               ;auxiliary type code
  180. SFFilename  ds       16              ;file name string  (prefix 0)
  181. SFPathname  ds       129             ;full path string (prefix 0)
  182.  
  183. SFPrompt    anop                     ;standard files prompt string
  184.             str      'Select an Ascii file to read:'
  185.  
  186. SFTypeList  anop                     ;list of file types to display
  187.             dc       i1'SFTypeCnt'   ;number of file types
  188.             dc       i1'$04'         ;TXT
  189.             dc       i1'$B0'         ;SRC
  190. SFTypeCnt   equ      *-SFTypeList-1  ;calculate number of file types
  191.  
  192. TextWindPtr ds       4               ;ptr to text window
  193.  
  194. TextWindStr ds       18              ;name string for text window
  195.  
  196. TextWind    anop                           ;window parmlist
  197.             dc       i2'TWEnd-TextWind'    ;size of table in bytes
  198.             dc       i2'%1101110110100101' ;description of frame
  199.             dc       i4'TextWindStr'       ;ptr to title string
  200.             dc       i4'0'                 ;refcon
  201.             dc       i2'0,0,0,0'           ;zoom size (full screen)
  202.             dc       i4'ColorTable'        ;ptr to color table
  203.             dc       i2'0,0'               ;content/data offset
  204. DataSize    dc       i2'0,1020'            ;data area height/width
  205.             dc       i2'0,0'               ;grow height/width
  206.             dc       i2'9,12'              ;arrow scroll vert/horiz
  207.             dc       i2'144,592'           ;page scroll vert/horiz
  208.             dc       i4'0'                 ;info bar refcon
  209.             dc       i2'0'                 ;info bar height
  210.             dc       i4'0'                 ;ptr to frame defproc
  211.             dc       i4'0'                 ;ptr to info bar defproc
  212.             dc       i4'WindUpdate'        ;ptr to update defproc
  213.             dc       i2'30,90,180,420'     ;coords of content region
  214.             dc       i4'-1'                ;plane (front)
  215.             dc       i4'0'                 ;ptr to memory
  216. TWEnd       anop
  217.  
  218. ColorTable  anop                ;color table for text window
  219.             dc       i2'$0000'  ;frame
  220.             dc       i2'$0F00'  ;title string and inactive title bar
  221.             dc       i2'$020F'  ;active title bar (racing stripes)
  222.             dc       i2'$00F0'  ;grow box and alert's middle outline
  223.             dc       i2'$00F0'  ;info bar and alert's inside outline
  224.  
  225. AlertStr    anop                     ;alert string
  226.             dc       c'0',i'60,160,115,480' ;coordinates
  227.             dc       c'4/'           ;caution icon, separator
  228.             dc       h'01',c'J',i'1' ;center text
  229.             dc       h'0D',c'Entire file cannot'  ;message text
  230.             dc       c' be displayed.',h'0D'
  231.             dc       c'/^#6'         ;separator, Continue default
  232.             dc       c'/#1'          ;separator, Cancel
  233.             dc       h'00'           ;zero terminator
  234.  
  235. MyFile      ds       17              ;input filename (GS/OS class 1)
  236.  
  237. OpenParm    anop                     ;Open parmlist (GS/OS class 1)
  238.             dc       i2'2'           ;pCount = 2 (input)
  239. OpenRefNum  ds       2               ;reference number (result)
  240.             dc       i4'MyFile'      ;ptr to filename (input)
  241.  
  242. ReadParm    anop                     ;Read parmlist (GS/OS class 1)
  243.             dc       i2'4'           ;pCount = 4 (input)
  244. ReadRefNum  ds       2               ;reference number (input)
  245. DataBuf     ds       4               ;ptr to data buffer (input)
  246. RequestCnt  ds       4               ;bytes requested (input)
  247. TransCnt    ds       4               ;bytes transferred (result)
  248.  
  249. CloseParm   anop                     ;Close parmlist (GS/OS class 1)
  250.             dc       i2'1'           ;pCount = 1 (input)
  251. CloseRefNum ds       2               ;reference number (input)
  252.             end
  253.  
  254. *****************************************************************
  255. *
  256. WindUpdate  start
  257. *
  258. * TaskMaster uses this code to update contents of window:
  259. *
  260. *****************************************************************
  261.             using    GlobalData
  262.  
  263. ; Since TaskMaster calls this subroutine, switch
  264. ; to application's data bank and direct page:
  265.  
  266.             phb                      ;save entry data bank
  267.             phd                      ;save entry direct page
  268.             phk                      ;equate program bank
  269.             plb                      ; with data bank
  270.             lda      MyDP            ;use application's
  271.             tcd                      ; direct page
  272.  
  273. ; Locate first visible line line in file:
  274.  
  275.             PushLong #WindPort       ;ptr to port rectangle's coords
  276.             _GetPortRect             ;get window's port rectangle
  277.  
  278.             lda      #9              ;row zero begins 9 pixels down
  279.             sta      RowLoc
  280.             ldy      #-1             ;prepare to zero file char indx
  281. CheckTop    lda      RowLoc          ;compare row position with
  282.             cmp      WindPort+top    ; top of port rectangle
  283.             bcs      DrawWind        ;first visible line located
  284. CheckEOF    iny                      ;compare file char index with
  285.             cpy      EOF             ; end-of-file position
  286.             bcs      Done            ;end of file found
  287.             lda      [DataBufPtr],y  ;get file char
  288.             and      #$FF            ;isolate lo byte
  289.             cmp      #$0D
  290.             bne      CheckEOF        ;CR not found
  291.             clc
  292.             lda      RowLoc          ;add 9 pixels for next row
  293.             adc      #9
  294.             sta      RowLoc
  295.             bra      CheckTop
  296.  
  297. ; Draw contents of window:
  298.  
  299. DrawWind    iny                      ;goto start of 1st visible line
  300.             phy                      ;protect file char index
  301.  
  302.             lda      #4              ;set left margin for
  303.             sta      LeftEdge        ; drawing in window
  304.  
  305.             pha                      ;horizontal coord (L edge)
  306.             PushWord RowLoc          ;vertical coord (row position)
  307.             _MoveTo                  ;put pen at specified point
  308.  
  309.             ply                      ;restore file char index
  310. NextLine    jsr      DrawLine        ;draw line in window
  311.             phy                      ;protect file char index
  312.  
  313.             PushLong #PenLoc         ;ptr to pen coordinates
  314.             _GetPen                  ;get pen position
  315.  
  316.             ply                      ;restore file char index
  317.             iny                      ;compare file char index with
  318.             cpy      EOF             ; end-of-file position
  319.             bcs      Done            ;end of file found
  320.  
  321.             lda      WindPort+bottom ;compare bottom of port
  322.             clc                      ; rectangle with current
  323.             adc      #9              ; vertical pen position
  324.             cmp      PenLoc+v
  325.             bcs      NextLine        ;not yet at bottom of window
  326.  
  327. Done        pld                      ;restore entry direct page
  328.             plb                      ;restore entry data bank
  329.             rtl                      ;RTL required by TaskMaster
  330. ;................................................................
  331. ;
  332. ; WindUpdate data:
  333. ;
  334. WindPort    ds       8               ;coords of port rectangle
  335. RowLoc      ds       2               ;row position in file
  336.             end
  337.  
  338. *****************************************************************
  339. *
  340. DrawLine    start
  341. *
  342. * Draw one line to window or printer:
  343. *
  344. *****************************************************************
  345.             using    GlobalData
  346.  
  347.             stz      CharCnt         ;zero char count
  348.             sty      RowStart        ;save starting position
  349. GetLine     lda      [DataBufPtr],y  ;get char
  350.             and      #$FF            ;isolate low byte
  351.             cmp      #$0D
  352.             beq      ShowLine        ;CR indicates end of line
  353.             inc      CharCnt         ;bump char count
  354.             iny                      ; and char index
  355.             cpy      EOF
  356.             bne      GetLine         ;end of file not found
  357.             dey                      ;end of file found
  358.  
  359. ShowLine    phy                      ;protect file char index
  360.             lda      CharCnt         ;if char count is zero
  361.             beq      MoveDown        ; then bare CR found
  362.  
  363.             clc                      ;calc ptr to start of line
  364.             lda      DataBufPtr
  365.             adc      RowStart
  366.             tax
  367.             lda      DataBufPtr+2
  368.             adc      #0
  369.  
  370.             pha                      ;hi byte of ptr to line
  371.             phx                      ;lo byte of ptr to line
  372.             PushWord CharCnt         ;number of bytes to draw
  373.             _DrawText                ;draw entire line
  374.  
  375. MoveDown    PushLong #PenLoc         ;get current pen location
  376.             _GetPen                  ; (at end of line)
  377.  
  378.             PushWord LeftEdge        ;horiz coord (left edge)
  379.             clc                      ;calculate vertical position
  380.             lda      PenLoc+v        ; by adding 9 to current
  381.             adc      #9              ; pen location
  382.             pha                      ;vert coord (line position)
  383.             _MoveTo                  ;put pen at specified location
  384.  
  385.             ply                      ;restore file char index
  386.             rts
  387. ;................................................................
  388. ;
  389. ; DrawLine data:
  390. ;
  391. CharCnt     ds       2               ;number of chars in row
  392. RowStart    ds       2               ;starting position of row
  393.             end
  394.  
  395. *****************************************************************
  396. *
  397. DoChooser   start
  398. *
  399. * Select printer and port driver via chooser dialog:
  400. *
  401. *****************************************************************
  402.  
  403.             pha                      ;space for result
  404.             _PrChoosePrinter         ;conduct chooser dialog
  405.             pla                      ;trash  Boolean: true = new
  406.             rts                      ; driver, false = same driver
  407.             end
  408.  
  409. *****************************************************************
  410. *
  411. DoSetup     start
  412. *
  413. * Select page setup via style dialog:
  414. *
  415. *****************************************************************
  416.  
  417.             jsr      SetPrintRec     ;set print record
  418.  
  419.             pha                      ;space for result
  420.             PushLong PrtRecHndl      ;handle to print record
  421.             _PrStlDialog             ;conduct setup dialog
  422.             pla                      ;trash Boolean: true = Okay
  423.             rts                      ; hit, false = Cancel hit
  424.             end
  425.  
  426. *****************************************************************
  427. *
  428. SetPrintRec start
  429. *
  430. * Establish default print record:
  431. *
  432. *****************************************************************
  433.             using    GlobalData
  434.  
  435.             lda      PrtRecHndl
  436.             ora      PrtRecHndl+2
  437.             beq      SPR01           ;print record not allocated
  438.  
  439.             anop                     ;validate current print record
  440.             pha                      ;space for result
  441.             PushLong PrtRecHndl      ;handle to print record
  442.             _PrValidate
  443.             jsr      HandlErr
  444.             pla                      ;trash Boolean: true = change,
  445.             rts                      ; false = no change
  446.  
  447. SPR01       anop                     ;allocate mem for print record
  448.             PushLong #0              ;space for result
  449.             PushLong #140            ;size of print record
  450.             PushWord MasterID        ;master ID
  451.             PushWord #$C010          ;locked, fixed, one bank
  452.             PushLong #0              ;not used
  453.             _NewHandle               ;allocate space
  454.             jsr      HandlErr
  455.             PullLong PrtRecHndl      ;save handle to data buffer
  456.  
  457.             lda      [PrtRecHndl]    ;dereference handle
  458.             sta      PrtRecPtr       ; to print record
  459.             ldy      #2
  460.             lda      [PrtRecHndl],y
  461.             sta      PrtRecPtr+2
  462.  
  463.             anop                     ;set default print record
  464.             PushLong PrtRecHndl      ;handle to print record
  465.             _PrDefault
  466.             jsr      HandlErr
  467.             rts
  468.             end
  469.  
  470. *****************************************************************
  471. *
  472. DoPrint     start
  473. *
  474. * Print contents of window:
  475. *
  476. *****************************************************************
  477.             using    GlobalData
  478.  
  479. ; Set default print record or validate current print record:
  480.  
  481.             jsr      SetPrintRec
  482.  
  483. ; Conduct job dialog:
  484.  
  485.             pha                      ;space for result
  486.             PushLong PrtRecHndl      ;handle to print record
  487.             _PrJobDialog
  488.             pla                      ;get Boolean
  489.  
  490.             bne      Printit         ;true = Okay hit so continue
  491.             rts                      ;false = Cancel hit so exit
  492.  
  493. Printit     _WaitCursor              ;display clock cursor
  494.  
  495.             ldy      #$50+6          ;get printing method byte
  496.             lda      [PrtRecPtr],y   ; in job subrecord of
  497.             and      #$FF            ; print record
  498.             sta      PrtMethod
  499.  
  500.             bne      DocStart        ;spooling; don't reset copies
  501.  
  502.             ldy      #$50+4          ;draft printing; get number
  503.             lda      [PrtRecPtr],y   ; of copies in job subrecord
  504.             sta      NumCopies       ; of print record
  505.  
  506.             lda      #1              ;ensure one copy in job sub-
  507.             sta      [PrtRecPtr],y   ; record of print record
  508.  
  509. ; Initialize document GrafPort and make it current:
  510.  
  511. DocStart    PushLong #0              ;space for result
  512.             PushLong PrtRecHndl      ;handle to print record
  513.             PushLong #0              ;allocate new GrafPort
  514.             _PrOpenDoc
  515.             PullLong PrtDocPtr       ;get ptr to doc's GrafPort
  516.             jsr      CheckPrtErr     ;check error
  517.             bcc      PrintLoop       ;no error
  518.             brl      DocDone         ;error, so abort printing
  519.  
  520. ; Execute printing loop:
  521.  
  522. PrintLoop   ldy      #0
  523. PageStart   sty      YSave           ;protect file char index
  524.  
  525.             PushLong PrtDocPtr       ;ptr to document's GrafPort
  526.             PushLong #0              ;no scaling
  527.             _PrOpenPage              ;begin new page
  528.             jsr      CheckPrtErr     ;check error
  529.             bcs      PageDone        ;error, so abort printing
  530.  
  531. PrintPage   ldy      #$02+6+bottom   ;get bottom of page in info
  532.             lda      [PrtRecPtr],y   ; subrecord of print record
  533.             sta      PageEnd
  534.  
  535.             lda      #0              ;set left margin for printing
  536.             sta      LeftEdge
  537.  
  538.             pha                      ;horizontal coordinate (L edge)
  539.             PushWord #9              ;vertical coordinate (1st row)
  540.             _MoveTo                  ;move pen to specified point
  541.  
  542.             ldy      YSave           ;restore file char index
  543. PrintLine   jsr      DrawLine        ;draw line to window or printer
  544.             sty      YSave           ;protect file char index
  545.  
  546.             PushLong #PenLoc         ;ptr to pen coordinates
  547.             _GetPen                  ;get pen position
  548.  
  549.             ldy      YSave           ;restore file char index
  550.             iny                      ;compare file char index with
  551.             cpy      EOF             ; end-of-file position
  552.             bcs      PageDone        ;end of file found
  553.  
  554.             lda      PenLoc+v
  555.             cmp      PageEnd
  556.             bcc      PrintLine       ;not at end of page
  557.  
  558.             sty      YSave           ;protect file char index
  559.  
  560.             PushLong PrtDocPtr       ;ptr to document's GrafPort
  561.             _PrClosePage             ;end printing of page
  562.             jsr      CheckPrtErr     ;check error
  563.             bcs      DocDone         ;error, so abort printing
  564.  
  565.             ldy      YSave           ;restore file char index
  566.             bra      PageStart       ;loop back for another page
  567.  
  568. ; Terminate printing loop:
  569.  
  570. PageDone    PushLong PrtDocPtr       ;ptr to document's GrafPort
  571.             _PrClosePage             ;end printing of page
  572.  
  573. DocDone     PushLong PrtDocPtr       ;ptr to document's GrafPort
  574.             _PrCloseDoc              ;close document's GrafPort
  575.  
  576.             pha                      ;space for result
  577.             _PrError
  578.             pla                      ;get last printer error code
  579.             bne      Done            ;error found; skip spooling
  580.  
  581.             lda      PrtMethod
  582.             beq      Spoolit         ;draft printing; skip mem check
  583.  
  584.             _CompactMem              ;compact memory
  585.  
  586.             PushLong #0              ;space for result
  587.             _MaxBlock
  588.             PullLong MaxBlkSize      ;size of largest free mem block
  589.  
  590.             lda      MaxBlkSize
  591.             cmp      #$2800
  592.             lda      MaxBlkSize+2
  593.             sbc      #0
  594.             bcc      Done            ;mem block < 10K; skip spooling
  595.  
  596. Spoolit     PushLong PrtRecHndl      ;handle to print record
  597.             PushLong #0              ;allocate new GrafPort
  598.             PushLong #0              ;allocate printer status record
  599.             _PrPicFile               ;print spooled document
  600.  
  601.             lda      PrtMethod
  602.             bne      Done            ;spool printing; don't recycle
  603.  
  604.             dec      NumCopies       ;draft printing, check copies
  605.             beq      Done            ;done
  606.             jsr      CheckPMBuf      ;ensure empty print buffer
  607.             bcs      Done            ;extended interface call error
  608.             brl      DocStart        ;draft-print another copy
  609.  
  610. Done        _InitCursor              ;show arrow cursor
  611.             rts
  612. ;................................................................
  613. ;
  614. ; Check for Print Manager error:
  615. ;
  616. CheckPrtErr bcc      CPE1            ;also check error location
  617.             rts
  618.  
  619. CPE1        pha                      ;space for result
  620.             _PrError                 ;check last error
  621.             pla                      ;get last PM error code
  622.  
  623.             sec                      ;assume error
  624.             bne      CPE2            ;error code found
  625.             clc                      ;signal no error
  626. CPE2        rts
  627. ;................................................................
  628. ;
  629. ; DoPrint data:
  630. ;
  631. YSave       ds       2        ;contents of Y-reg
  632. NumCopies   ds       2        ;number of copies to be printed
  633. PrtMethod   ds       2        ;printing method (0=draft, non0=spool)
  634. PrtDocPtr   ds       4        ;ptr to document's GrafPort
  635. PageEnd     ds       2        ;bottom of page rectangle
  636. MaxBlkSize  ds       4        ;size of largest free memory block
  637.             end
  638.  
  639. *****************************************************************
  640. *
  641. CheckPMBuf  start
  642. *
  643. * Ensure empty buffer using extended serial port firmware calls:
  644. *
  645. *****************************************************************
  646.             using    GlobalData
  647.  
  648. PortNamePtr gequ     $18             ;ptr to name of active device
  649. EIHndl      gequ     $1C             ;handle to bank zero space
  650. EIPtr       gequ     $20             ;ptr to bank zero space
  651. Emulstack   gequ     $010100         ;emulation mode stack ptr
  652.  
  653. ; Find slot number of printer:
  654.  
  655. CheckPMBuf  anop
  656.  
  657.             PushLong #0              ;space for result
  658.             ldx      #$2913          ;PrGetPortDvrName
  659.             jsl      $E10000
  660.             PullLong PortNamePtr     ;ptr to name of driver
  661.  
  662.             short                    ;set 8-bit regs
  663.             ldy      #2
  664.             lda      [PortNamePtr],y ;get 1st char in device name
  665.             and      #$DF            ;ensure upper case
  666.             cmp      #'A'
  667.             bne      GetSlot         ;parallel card not found
  668.             sec                      ;parallel card found so abort
  669.             rts
  670.  
  671. GetSlot     ldx      #1
  672.             txy
  673.             lda      [PortNamePtr],y ;get 1st char in device name
  674.             and      #$DF            ;ensure upper case
  675.             cmp      #'M'
  676.             bne      GotSlot         ;starts with "P" = printer
  677.             inx                      ;starts with "M" = modem
  678. GotSlot     txa                      ;A-reg holds printer's slot
  679.  
  680. ; Modify code to reflect printer's slot ROM:
  681.  
  682.             ora      #$C0            ;get printer's slot ROM address
  683.             sta      GetOffset+2     ;modify calls
  684.             sta      DoOutBuf+2
  685.             sta      DoQStat+2
  686.  
  687. ; Modify code to reflect extended interface dispatch address:
  688.  
  689. GetOffset   lda      >$C012          ;get offset to dispatch address
  690.             sta      DoOutBuf+1      ;modify calls
  691.             sta      DoQStat+1
  692.  
  693. ; Allocate bank zero space for extended interface command calls:
  694.  
  695.             long                     ;set 16-bit regs
  696.             PushLong #0              ;space for result
  697.             PushLong #BZEnd-BZStart  ;size of direct page space
  698.             PushWord MasterID        ;master ID
  699.             PushWord #$C005          ;lock, fix, align, fixed bank
  700.             PushLong #0              ;bank zero is the fixed bank
  701.             _NewHandle               ;allocate space
  702.             jsr      HandlErr
  703.             PullLong EIHndl          ;save handle to bank zero space
  704.  
  705.             lda      [EIHndl]        ;dereference handle to get
  706.             sta      EIPtr           ; ptr to bank zero space
  707.             sta      GoBZ+1          ;modify bank zero call addr
  708.             ldy      #2
  709.             lda      [EIHndl],y
  710.             sta      EIPtr+2
  711.  
  712. ; Copy image of bank zero code to bank zero:
  713.  
  714.             shortm                   ;set 8-bit A and memory
  715.             ldy      #BZEnd-BZStart-1
  716. CopyLoop    lda      BZStart,y
  717.             sta      [EIPtr],y
  718.             dey
  719.             bpl      CopyLoop
  720.             longm                    ;set 16-bit A and memory
  721.  
  722. ; Invoke extended interface calls which now reside in bank zero:
  723.  
  724. GoBZ        jsl      $001000         ;modified above
  725.  
  726. ; Dispose of handle to bank zero:
  727.  
  728.             PushLong EIHndl
  729.             _DisposeHandle
  730.  
  731. ; Check for extended interface call error and return to caller:
  732.  
  733.             lda      GOBReturn
  734.             bne      ExtCmdErr       ;call error
  735.             lda      OQSReturn
  736.             beq      CPMBRTS         ;no call error
  737. ExtCmdErr   sec                      ;flag error
  738. CPMBRTS     rts
  739. ;................................................................
  740. ;
  741. ; IMAGE OF BANK ZERO CODE (this code copied to bank zero):
  742. ;
  743. ; Save entry environment:
  744.  
  745. BZStart     phd                      ;save entry direct page
  746.             phb                      ;save entry data bank
  747.             tsc                      ;get stack ptr into
  748.             tax                      ; A and X regs
  749.             shortm                   ;set 8-bit A and memory
  750.             xba
  751.             dec      a
  752.             beq      SaveSP          ;stack ptr already in page 1
  753.             lda      #1              ;set stack to page one
  754.             xba
  755.             lda      Emulstack       ;set emulation mode stack ptr
  756.             tcs                      ; (don't worry about hi byte)
  757. SaveSP      phx                      ;save entry stack ptr
  758.  
  759. ; Enter emulation mode and set new environment:
  760.  
  761.             emulation                ;enter emulation mode
  762.             pea      0               ;put direct page into page zero
  763.             pld
  764.             lda      #0              ;zero program bank
  765.             pha
  766.             plb
  767.  
  768. ; Ensure empty printer buffer via extended interface calls:
  769.  
  770. TestBuf     emulation                ;enter emulation mode
  771.             lda      #GOBCmdList     ;point to command list
  772.             ldx      #>GOBCmdList
  773.             ldy      #^GOBCmdList
  774. DoOutBuf    jsr      $C000           ;modified to call GetOutBuffer
  775.             lda      >GOBReturn
  776.             bne      RestEnviron
  777.  
  778.             lda      #OQSCmdList     ;point to command list
  779.             ldx      #>OQSCmdList
  780.             ldy      #^OQSCmdList
  781. DoQStat     jsr      $C000           ;modified to call OutQStatus
  782.             lda      >OQSReturn
  783.             bne      RestEnviron
  784.  
  785.             native   long            ;set native mode, 16-bit regs
  786.             lda      >GOBBufLen      ;ensure empty print buffer
  787.             dec      a
  788.             cmp      >OQSBufLen
  789.             bne      TestBuf
  790.  
  791. ; Reenter native mode and restore environment:
  792.  
  793. RestEnviron native   long            ;set native mode, 16-bit regs
  794.             plx                      ;restore entry stack ptr
  795.             txs
  796.             plb                      ;restore entry data bank
  797.             pld                      ;restore entry direct page
  798.             rtl
  799. BZEnd       anop
  800. ;................................................................
  801. ;
  802. ; CheckPMBuf data (this code not copied to bank zero):
  803. ;
  804. GOBCmdList  anop              ;GetOutBuffer command list
  805.             dc       h'04'    ;pCount = 4
  806.             dc       h'11'    ;command code
  807. GOBReturn   ds       2        ;return code (output)
  808.             ds       4        ;buffer address (output)
  809. GOBBufLen   ds       2        ;buffer length (output)
  810.  
  811. OQSCmdList  anop              ;OutQStatus
  812.             dc       h'04'    ;pCount = 4
  813.             dc       h'17'    ;command code
  814. OQSReturn   ds       2        ;return code (output)
  815. OQSBufLen   ds       2        ;space remaining in buffer (output)
  816.             ds       2        ;reserved (output)
  817.             end
  818.